package com.baizhiedu.basic.interceptor;

import org.springframework.lang.Nullable;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashSet;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * @Author: robert.song
 * @Date: Created in 2021/11/9
 */
public class MyInterceptor implements HandlerInterceptor {
    //    在目标方法执行前执行
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("prehandler");

        return true;
    }

    //    在目标方法执行后、视图对象返回前执行
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception {
        if (null == null) {
            throw new NullPointerException();
        }
        System.out.println("posthandler");
    }

    //      流程结束后执行
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception {
        System.out.println("aftercompletion");
    }
}
